package neusoft.edu.cn.guanshangshiguang.activities;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import neusoft.edu.cn.guanshangshiguang.Listener.Listener;
import neusoft.edu.cn.guanshangshiguang.R;
import neusoft.edu.cn.guanshangshiguang.bean.shenqingBean;
import neusoft.edu.cn.guanshangshiguang.model.shenqingModel;

public class shenqingActivity extends AppCompatActivity {

    private EditText bname,content,xinjiu,leixing;
    private Button tijiao;
    private shenqingBean shenqingBean;

    private Listener listener = new Listener() {
        @Override
        public void onResponse(Object o) {
            shenqingBean = (shenqingBean)o;
            if(shenqingBean.getCode()==1){
                Intent intent = new Intent(getApplicationContext(),ChangeDetailsActivity.class);
                Toast.makeText(shenqingActivity.this, "申请成功", Toast.LENGTH_SHORT).show();
                startActivity(intent);
                finish();

            }else{
                Toast.makeText(shenqingActivity.this, "申请失败，请稍后重试", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(shenqingActivity.this, "申请失败，请重试", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar actionBar = getSupportActionBar();//去掉标题栏
        actionBar.hide();//去掉标题栏
        setContentView(R.layout.activity_shenqing);

        init();

        tijiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shenqingModel shenqingModel = new shenqingModel();
                shenqingModel.getResultList(LoginActivity.UserId,getIntent().getStringExtra("change_id").toString(),
                        MainActivity.User_School,content.getText().toString(),bname.getText().toString(),
                        xinjiu.getText().toString(),leixing.getText().toString(),listener);
            }
        });
    }

    private void init() {
        bname=findViewById(R.id.textView26);
        content=findViewById(R.id.textView27);
        xinjiu=findViewById(R.id.textView28);
        leixing=findViewById(R.id.textView29);
        tijiao=findViewById(R.id.button4);
    }
}
